package cn.bytets.rpc.api.protocol;

import cn.bytets.rpc.api.invoke.AsyncToSyncInvoker;
import cn.bytets.rpc.api.invoke.Invoker;
import cn.bytets.rpc.common.URL;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public abstract class AbstractProtocol implements Protocol{

    protected final Map<Invoker<?>,Object> invokers = new ConcurrentHashMap<Invoker<?>,Object>();

    @Override
    public int getDefaultPort() {
        return 28080;
    }

    @Override
    public void destroy() {

    }

    @Override
    public <T> Invoker<T> refer(Class<T> type, URL url) {
        return new AsyncToSyncInvoker<T>(buildInvoker(type,url));
    }

    public abstract <T> Invoker<T> buildInvoker(Class<T> type, URL url);
}
